package models;

import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 异步流上下文（工作台）
 */
@Data
@SuppressWarnings("unchecked")
public class AsyncFlowData<TAsyncContext> {
    //节点日志
    private List<AsyncFlowNodeLogEntity> asyncFlowNodeLogEntityList = Collections.synchronizedList(new ArrayList<>());
    //节点明细日志【AsyncFlowCommon_Log.AddAsyncFlowDetailLog()放在此集合中】
    private List<AsyncFlowNodeDetailLogEntity> asyncFlowNodeDetailLogEntityList = Collections.synchronizedList(new ArrayList<>());
    //业务日志【AsyncFlowBusinessLog.addBusinessLog()放在此集合中】
    private List<AsyncFlowBusinessLogEntity> asyncBusinessLogEntityList = Collections.synchronizedList(new ArrayList<>());
    //需要执行的sql【AsyncFlowBuildSql类中的各个方法生成的SQL语句放在此集合中】
    private List<ExecuteSql> executeSQLs = Collections.synchronizedList(new ArrayList<>());
    //数据源（从数据库中查询出来的 ;表名-具体实体）【数据库冲查出的所有实体】
    private ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<>();
    //数据库名称和数据库的SessionFactory
    private Map<String, String> dataBaseInfo = new HashMap<>();
    //节点流信息
    private AsyncFlowInfo asyncFlowInfo = null;
    //测试上下文【在本地测试环境，使用显示的测试数据测试时才有值】
    private String TESTContext;
    //测试请求参数【在本地测试环境，使用显示的测试数据测试时才有值】
    private String TESTRequest;
    //异步流具体上下文
    private TAsyncContext context;

    /**
     * 执行完设置返回参数之后会有值【在异步操作中可以使用来判断节点是否执行成功】
     */
    private AsyncFlowResponse<?> asyncFlowResponse = new AsyncFlowResponse();


    public <T> T getDBData(String dataName) {
        if (StringUtils.isBlank(dataName)) {
            return null;
        }
        Object data = dataMap.get(dataName);
        if (data == null) {
            return null;
        } else {
            return (T) dataMap.get(dataName);
        }

    }



}
